feat(query): Implement Vector Index with HNSW Algorithm #18134
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I hereby agree to the terms of the CLA available at: https://docs.databend.com/dev/policies/cla/
Summary
This PR introduces a vector index to Databend, leveraging the Hierarchical Navigable Small World (HNSW) algorithm for efficient similarity search.
Key Features:
Vector Index with HNSW: Implements a vector index based on the HNSW algorithm, enabling fast and accurate approximate nearest neighbor search on
VECTOR
data. Creating a vector index requires specifying the following parameters to fine-tune performance and accuracy:m
: Controls the number of connections (edges) per node in the HNSW graph. Higher values generally improve recall but increase index size and construction time.ef_construct
: Controls the search width during index construction, representing the number of neighbors considered during the building process. Higher values lead to better index quality but increase construction time.distance
: Specifies the supported distance calculation function(s) for the index. Acceptable values arecosine
,l1
, andl2
. Multiple distance functions can be configured for a single index.Distance Function Support: Provides comprehensive distance metric support for various similarity calculations:
cosine_distance
: Calculates the cosine distance between vectors, suitable for measuring the angle between vectors and identifying semantic similarity.l1_distance
: Calculates the L1 distance (Manhattan distance) between vectors.l2_distance
: Calculates the L2 distance (Euclidean distance) between vectors.L1 Distance Function Implementation: As part of this PR, the
l1_distance
function was implemented to provide a complete set of distance functions.Implementation Details:
The implementation of the HNSW algorithm is primarily based on modifications to the excellent open-source HNSW implementation from github.com/qdrant/qdrant. We would like to express our sincere gratitude to the
Qdrant
team for their valuable work, which significantly accelerated the development of this feature.Example Usage:
part of: #17972
Tests
Type of change
This change is